package com.hdd.hll.common.redis.config;

import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * redisson 配置类
**/
@Configuration
public class RedissonConfig {

    @Autowired
    RedisProperties redisProperties;
    @Bean
    public RedissonClient getRedisson(){
        Config config = new Config();
        SingleServerConfig serverConfig =  config.useSingleServer();
        serverConfig.setAddress("redis://" + redisProperties.getHost() + ":" + redisProperties.getPort());
        if(!StringUtils.isEmpty(redisProperties.getPassword())){
            serverConfig.setPassword(redisProperties.getPassword());
        }
        return Redisson.create(config);
    }

}